package com.frank.game.base;

import com.frank.game.base.unit.Unit;
import com.frank.game.rule.CreateRule;
import com.frank.game.tool.GetProperties;
import com.frank.game.tool.Tools;

/**
 * @deprecated:区域
 * @author frank
 * @date 2015年12月15日
 */
public class Area {
	
	/**长度**/
	private int length;
	/**宽度**/
	private int width;
	/**高度**/
	private int height;
	/**温度**/
	private double temp;
	/**重力**/
	private double gravity;
	/**类型**/
	private AreaType type;
	/**物品**/
	public Unit[][][] units;
	
	public Area(AreaType type) {
		this.length = (int)Tools.getRandom(
				Integer.valueOf(GetProperties.getPropertieValue("MIN_AREA_LENGTH")), 
				Integer.valueOf(GetProperties.getPropertieValue("MAX_AREA_LENGTH")));
		this.width = (int)Tools.getRandom(
				Integer.valueOf(GetProperties.getPropertieValue("MIN_AREA_WIDTH")), 
				Integer.valueOf(GetProperties.getPropertieValue("MAX_AREA_WIDTH")));
		this.height = (int)Tools.getRandom(
				Integer.valueOf(GetProperties.getPropertieValue("MIN_AREA_HEIGHT")), 
				Integer.valueOf(GetProperties.getPropertieValue("MAX_AREA_HEIGHT")));
		this.gravity = 1;
		this.temp = 25;
		this.type = type;
		initUnits();
	}
	
	public void initUnits(){
		this.units = new Unit[length][width][height];
		for (int x = 0; x < length; x++) {
			for (int y = 0; y < width; y++) {
				for (int z = 0; z < height; z++) {
					units[x][y][z] = CreateRule.getUnit(x, y, z, this);
				}
			}
		}
	}

	public Unit getUnit(int x, int y, int z) throws Exception {
		if(x < 0 || y < 0 || z < 0 || x > length || y > width || z > height){
			throw new Exception("获取物品时下标超过限制");
		}
		return units[x][y][z];
	}
	
	public int getLength() {
		return length;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public double getTemp() {
		return temp;
	}

	public void setTemp(double temp) {
		this.temp = temp;
	}

	public double getGravity() {
		return gravity;
	}

	public void setGravity(double gravity) {
		this.gravity = gravity;
	}

	public AreaType getType() {
		return type;
	}
	
	public enum AreaType{
		/**平原**/
		plain,
		/**森林**/
		forest,
		/**山丘**/
		hill,
		/**山脉**/
		mountain,
		/**地穴**/
		burrow,
		/**山洞**/
		cave,
		/**天空**/
		air
	}
	public String toString() {
		String str = "";
		switch (this.type) {
		case plain:
			str = "平原";
			break;
		case forest:
			str = "森林";
			break;
		case hill:
			str = "山丘";
			break;
		case mountain:
			str = "山脉";
			break;
		case burrow:
			str = "地穴";
			break;
		case cave:
			str = "山洞";
			break;
		case air:
			str = "天空";
			break;
		default:
			str = "其他";
			break;
		}
		return str;
	}
}
